package repo

import (
	"go-admin-server/app/dao"
	"go-admin-server/app/dao/model"
)

var RoleRepo = new(roleRepo)

type roleRepo struct{}

func (a *roleRepo) Create(item *model.Role) error {
	return dao.DB.Create(item).Error
}

func (a *roleRepo) Update(id uint64, item *model.Role) error {
	return dao.DB.Where("id=?", id).Updates(item).Error
}

func (a *roleRepo) Delete(id uint64) error {
	return dao.DB.Where("id=?", id).Delete(&model.Role{}).Error
}

func (a *roleRepo) UpdateStatus(id uint64, status int) error {
	return dao.DB.Where("id=?", id).Update("status", status).Error
}

func (a *roleRepo) QueryByRoleCodes(codes []string) (list []*model.Role, err error) {
	err = dao.DB.Where("code IN (?)", codes).Where("status=?", 1).Order("sort_order desc").Find(&list).Error
	return list, err
}
